/*
 * @Author: moonwater 13812995013@163.com
 * @Date: 2025-03-04 15:35:44
 * @LastEditors: moonwater 13812995013@163.com
 * @LastEditTime: 2025-03-04 15:35:58
 * @FilePath: \盐师22Git仓库\day07\SetBit.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package day07;

public class SetBit {
    public static int setBit(int v, int n) {
        // 使用位运算将第n位置为1
        return v | (1 << n);
    }
 
    public static void main(String[] args) {
        int v = 10; // 示例值，二进制表示为 1010
        int n = 2; // 要将第2位置为1
        
        int result = setBit(v, n);
        
        // 打印结果值及其二进制表示
        System.out.println("Original value: " + v + " (" + Integer.toBinaryString(v) + ")");
        System.out.println("Modified value: " + result + " (" + Integer.toBinaryString(result) + ")");
    }
}
